<include file="Public/mobile_head"/>
<!--<script type="text/javascript" src="{:ADDON_PUBLIC_PATH}/mobile/shop.js?v={:SITE_VERSION}"></script>-->
<link href="{:ADDON_PUBLIC_PATH}/mobile/common.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<link href="{:CUSTOM_TEMPLATE_PATH}Public/shop.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<body>
<script type="text/javascript">
$(function(){
	//购物添加数量
	$('.buy_count .add').click(function(){
		var val = Number($(this).siblings('input').val());
		if(val<1){
			$(this).siblings('input').val(1);
		}else{
			$(this).siblings('input').val(val+1);
		}
		updatePriceAndCount();
	})
	$('.buy_count .reduce').click(function(){
		var val = Number($(this).siblings('input').val());
		if(val>1){
			$(this).siblings('input').val(val-1);
			updatePriceAndCount();
		}else{
			$(this).siblings('input').val(1);
			updatePriceAndCount();
		}
	})
	$('.buy_count input[type="text"]').keyup(function(){
		if($(this).val()==0){
			//$.Dialog.fail("购物数量不能小于1件");
			//$(this).val(1);
		}else{
			updatePriceAndCount();
		}
	})
	$('input[name="goods_ids[]"]').change(function(){
		updatePriceAndCount();
	})
	
	//全选的实现
	$(".check_all").click(function(){
		if($('input[name="checkAll"]').prop('checked')==true){
		$('input[name="goods_ids[]"]').prop('checked',true);
		
		}else{
			$('input[name="goods_ids[]"]').prop('checked',false);
		}
		updatePriceAndCount();
	});
	
})
//更新购物车价格和数量
function updatePriceAndCount(){
	var totalCount = 0;
	var totalPrice = 0;
	if($('input[name="goods_ids[]"]:checked').size()==$('input[name="goods_ids[]"]').size()){
		$('input[name="checkAll"]').prop('checked',true);
	}else{
		$('input[name="checkAll"]').prop('checked',false);
	}
	$('input[name="goods_ids[]"]:checked').each(function(index, element) {
		var itemElem = $(this).parents('li');
		var price = parseFloat(itemElem.find('.singlePrice').text());
		var count = parseInt(itemElem.find('input[rel="buyCount"]').val());
		totalCount += count;
		totalPrice += count*price
	});
	$('#totalCount').text(totalCount);
	$('#totalPrice').text(totalPrice);
}
//提交检查
function checkCartSubmit(){
	if($('input[name="goods_ids[]"]:checked').size()==0){
		$.Dialog.fail("请先选择要购买的商品");
		return false;
	}
}
function confirmGetGoods(url){
	$.Dialog.confirmBox('温馨提示','确认已收货？',{rightCallback:function(){
		$.Dialog.loading();
		$.post(url,function(res){
			 setTimeout(function(){
				 location.reload();	
			},1500);			
	    });
	}});
}

</script>
    <div class="container">
        <!-- 店标和名称 -->
        <div class="shop_row">
			<div class="shop_row_img">
				<img src="{:CUSTOM_TEMPLATE_PATH}Public/xintu5.jpg" />
				<div class="shop_row_title">
					{$page_title}
				</div>
				<a href="{:U('lists',array('shop_id'=>$shop_id,'cid'=>$fenlei[id]))}" style="position:absolute;left:5px;top:50%;margin-top:-15px;color:#fff;font-size:30px;display:block;width:30px;height:30px;line-height:30px;">
					<img src="{:CUSTOM_TEMPLATE_PATH}Public/fanhui.png" style="width:100%;" />
				</a>
			</div>
        </div>
		
        	
        <!-- 详情信息 -->
        <form id="detailForm" action="{:addons_url('Shop://Wap/confirm_order')}" method="post">
        <input type="hidden" name="goods_id" value="{$goods.id}"/>
        <div class="detail_info">
        	<div class="info_item">
        		<h6 class="name">{$goods.title}</h6>
            	<p class="price">
                	￥<span id="price">{$goods.price|wp_money_format}</span>
                	
                </p>
            	<p class="beizhu">
					<span style="float:left;text-align:left;">
					截止时间：{$fenlei.end_time|date='Y-m-d H:i:s',###}
					</span>
					<php>
					if($goods['price']<=1){
					</php>
						<span style="float:right;text-align:right;">
						已有 {$goods.sale_count}份爱心
						</span>
					<php>
					}else{
					</php>
						<span style="float:right;text-align:right;">
						限额 {$goods.inventory}份 | 剩余 {$goods.shengyu}份
						</span>
					<php>
					}
					</php>
					<div style="clear:both;"></div>
                </p>
            </div>
			<php>
			if($goods['price']<=1){
			</php>
				<div class="info_item">
					<p>爱心份数</p>
					<div class="">
						<select name="buyCount" style="width:auto;min-width:80px;">
							<option value="1">1</option>
							<option value="5">5</option>
							<option value="10">10</option>
							<option value="20">20</option>
							<option value="50">50</option>
							<option value="100">100</option>
						</select>
						
					</div>
				</div>
			<php>
			}else{
			</php>
				<input type="hidden" name="buyCount" readonly value="1"/>
			<php>
			}
			</php>
        </div>
        <!-- 众筹介绍 -->
        <div class="detail_content">
            <div class="content">
			{$goods.content}
            </div>
        </div>
        </form>
    </div>
        <!-- 分类目录 -->
    
    <!-- 底部加入购物车等 -->
	<div class="bottom_menus"> 
		<a class="home" href="{:U('index', array('shop_id'=>$shop_id,'cid'=>$fenlei[id]))}"></a> 
		
		<php>
		//$kaishitime=strtotime("2016-05-20 12:00:00");
		$kaishitime=$fenlei['start_time'];
		if(time()<=$kaishitime){
			$shengyutime=$kaishitime-time();
			$shengyuhour=floor($shengyutime / (60 * 60));
			$shengyuminute = floor($shengyutime / 60) - ($shengyuhour * 60);
			$shengyusecond = floor($shengyutime) - ($shengyuhour * 60 * 60) - ($shengyuminute * 60);
			if ($shengyuminute <= 9) $shengyuminute = '0'.$shengyuminute;
			if ($shengyusecond <= 9) $shengyusecond = '0'.$shengyusecond;
			if($shengyuhour>0){
				$shengyutext="<span id='hour_show'>".$shengyuhour.":</span><span id='minute_show'>".$shengyuminute.":</span><span id='second_show'>".$shengyusecond."</span>";
			}else{
				if($shengyuminute>0){
					$shengyutext="<span id='minute_show'>".$shengyuminute.":</span><span id='second_show'>".$shengyusecond."</span>";
				}else{
					$shengyutext="<span id='second_show'>".$shengyusecond."</span>";
				}
			}
		</php>
			
			<a class="zcbtn" id="weikaishi" href="javascript:;" >倒计时 {$shengyutext}</a> 
			<a class="zcbtn" id="yikaishi" href="javascript:;" onClick="buyNow()" style="display:none;">确认支持</a> 
			<a class="center" href="{:U('user_center', array('shop_id'=>$shop_id,'cid'=>$fenlei[id]))}"></a> 
			<style type="text/css">
			.zcbtn span{display:line;}
			</style>
			<script type="text/javascript">
			
			var intDiff = parseInt({$shengyutime});//倒计时总秒数量
			function timer(intDiff){
				window.setInterval(function(){
				var hour=0,
					minute=0,
					second=0;//时间默认值		
				if(intDiff > 0){
					hour = Math.floor(intDiff / (60 * 60));
					minute = Math.floor(intDiff / 60) - (hour * 60);
					second = Math.floor(intDiff) - (hour * 60 * 60) - (minute * 60);
				}else{
					$("#weikaishi").hide();
					$("#yikaishi").show();
				}
				if (minute <= 9) minute = '0' + minute;
				if (second <= 9) second = '0' + second;
				if(hour>0){
					$('#hour_show').html('<s id="h"></s>'+hour+':');
					$('#minute_show').html('<s></s>'+minute+':');
					$('#second_show').html('<s></s>'+second+'');
				}else{
					$('#hour_show').hide();
					if(minute>0){
						$('#minute_show').html('<s></s>'+minute+':');
						$('#second_show').html('<s></s>'+second+'');
					}else{
						$('#minute_show').hide();
						$('#second_show').html('<s></s>'+second+'');
					}
				}
				intDiff--;
				}, 1000);
			} 
			$(function(){
				timer(intDiff);
			});	
			</script>
		<php>
		}else{
			$jieshutime=$fenlei['end_time'];
			if(time()>$jieshutime){
		</php>
				<a class="zcbtn" href="javascript:;" >活动已结束</a> 
				<a class="center" href="{:U('user_center', array('shop_id'=>$shop_id,'cid'=>$fenlei[id]))}"></a> 
		<php>
			}else{
		</php>
			<php>
			if($goods['shengyu']<1){
			</php>
				<a class="zcbtn" href="javascript:;" style="background:#ccc;">确认支持</a> 
			<php>
			}else{
			</php>
				<a class="zcbtn" href="javascript:;" onClick="buyNow()">确认支持</a> 
			<php>
			}
			</php>
			<a class="center" href="{:U('user_center', array('shop_id'=>$shop_id,'cid'=>$fenlei[id]))}"></a> 
		<php>
			}
		}
		</php>
		
		<div class="showerweima_box">
			<div class="showerweima_img">
				请关注4into公众号后支持
				<img src="/showerweima.jpg" />
				<a class="close_btn" onClick="hideerweima()"></a>
			</div>
		</div>
		<input type="hidden" id="user_midsfgz" value="{$user_midsfgz}" />
		<style type="text/css">
		.showerweima_box{width:100%;height:100%;padding-top:10px;text-align:center;left:0;top:0px;background:#fff;position:fixed;z-index:999;display:none;}
		.showerweima_img{ position:relative;margin:10px auto;width:90%;background:#fff;max-width:430px;text-align:center;}
		.showerweima_img img{width:100%;text-align:center;}
		.showerweima_img .close_btn{display:block;width:30px;height:30px;position:absolute;z-index:10;background:url(/close.png) no-repeat;right:5px;top:-5px; cursor:pointer;}

		</style>
		<script type="text/javascript">
		function showerweima(){
			$(".showerweima_box").show();
			window.scrollTo(0,0);
		}
		function hideerweima(){
			$(".showerweima_box").hide();
		}
		</script>
		
		
	</div>
	<p class="copyright">{$system_copy_right}{$tongji_code}</p>
<script type="text/javascript">
//加入收藏
function addToFavorite(){
	$.Dialog.loading();
	var data = $('#detailForm').serializeArray();
	$.ajax({
		url:"{:U('addToCollect',array('shop_id'=>$shop_id))}",
		data:data,
		dataType:'JSON',
		type:"POST",
		success:function(data){
			if(data){
				$.Dialog.success("收藏成功");
			}
		}
	})
}
function addToCart(){
	
	if(Number($('input[name="buyCount"]').val())<1){
		$.Dialog.fail("购物数量不能小于1件");
		return;	
	}
//	if(!$('.sku_check:checked').val()){
//		$.Dialog.fail("请选择型号");
//		return;	
//	}
	$.Dialog.loading();
	var data = $('#detailForm').serializeArray();
	$.ajax({
		url:"{:U('addToCart',array('shop_id'=>$shop_id))}",
		data:data,
		dataType:'html',
		type:"POST",
		success:function(res){
			if(res){
				$.Dialog.success("加入购物车成功");
				$('#cartCount').text(res);
			}
		}
	})
}
function buyNow(){
	if($("#user_midsfgz").val()<=0 || $("#user_midsfgz").val()=="" || $("#user_midsfgz").val()=="NULL"){
		showerweima();
		return;
	}
	if(Number($('input[name="buyCount"]').val())<1){
		$.Dialog.fail("购物数量不能小于1件");
		return;	
	}
//	if(!$('.sku_check:checked').val()){
//		$.Dialog.fail("请选择型号");
//		return;	
//	}
	$('#detailForm').submit();
}
$(function(){
	$.WeiPHP.gallery('.photoList','.photoList ul');
	$('.sku_item').click(function(){
		$('#price').text($(this).data('price'));
		$(this).addClass('select').siblings().removeClass('select');
		$(this).find('input').prop("checked",true);
		$(this).siblings().find('input').prop("checked",false);
	})
	//图片预览
	var picList = [];
	$('.photoList li img').each(function(index, element) {
		var picUrl = $(this).attr("src");
		picList[index] = picUrl;
        $(this).click(function(){
			wx.previewImage({
				current: picUrl, // 当前显示的图片链接
				urls: picList // 需要预览的图片链接列表
			});
		})
    });
	
		//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search_form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});	
});

</script>	

</body>
</html>